f=file("problem 22.txt","r")
S=f.read().split('","')
S[0]=S[0][1:]
S[-1]=S[-1][:-1]
S.sort()
def score(string):
   return  sum([ord(i)-64 for i in list(string)])*(S.index(string)+1)
print sum([score(i) for i in S])
    
